package com.zy.algorithm.v3.array

import android.content.Intent
import com.zy.view.DIYSortView
import com.zy.utils.data.Point

//https://leetcode.cn/problems/merge-sorted-array/?envType=study-plan-v2&envId=top-interview-150
open class LeetCode0088 : BaseV3ArrayFragment() {
    private var array1 = intArrayOf(1, 3, 8, 9, 12, 0, 0, 0, 0, 0)
    private var array2 = intArrayOf(2, 4, 5, 7, 10)

    private val ass1 =
        builder.setOriginX(7).setOriginY(1).setV("V").setIndex(Point.ASS_INDEX).build(
            Point.Type.SUB_SCRIPT
        )

    private val ass2 =
        builder.setOriginX(7).setOriginY(4).setV("V").setIndex(Point.ASS_INDEX).build(
            Point.Type.SUB_SCRIPT
        )

    private val assFinal =
        builder.setOriginX(12).setOriginY(1).setV("V").setIndex(Point.ASS_INDEX).build(
            Point.Type.SUB_SCRIPT
        )

    override fun getInitD(): Int {
        return 150
    }

    override fun setData(diyV4: DIYSortView) {
        diyV4.changeType = DIYSortView.TYPE_COVER
        diyV4.setD(getInitD())

        if (code == 1) {
            array1 = intArrayOf(
                1, 2, 3, 4, 10, 0, 0, 0, 0, 0
            )
            //diyV4.addNoMoveAssistList(1, 2, array1, Point.Type.DEFAULT)
            array2 = intArrayOf(
                5, 6, 7, 8, 9,
            )
        } else if (code == 2) {
            array1 = intArrayOf(
                5, 6, 7, 8, 9, 0, 0, 0, 0, 0
            )
            //diyV4.addNoMoveAssistList(1, 2, array1, Point.Type.DEFAULT)
            array2 = intArrayOf(
                1, 2, 3, 4, 10
            )
        }
        diyV4.create(3, 2, array1, Point.Type.DEFAULT)
        diyV4.create(3, 5, array2, Point.Type.DEFAULT)

        //diyV4.addNoMoveAssistList(1, 5, array2, Point.Type.DEFAULT)

        //diyV4.addAss(1, 1, "V")
        addAss()
    }

    private fun addAss() {
        diyV4.addPoint(ass1)
        diyV4.addPoint(ass2)
        diyV4.addPoint(assFinal)
        diyV4.postInvalidate()
    }


    //adb shell am broadcast -a com.zy.test.DataTest --ei code 1 --ei type 1
    override fun onDIYReceive(intent: Intent) {
        val code = intent.getIntExtra("code", 0)
        when (code) {
            0 -> {//add 下标
                addAss()
            }
            1 -> { //num1 和 total index --

            }
            2 -> {//num2 和 total index --

            }
            else -> {

            }
        }

    }
}